public class attendance_controller {

public List<Attendance_Record__c> listAttendance{get; set;}
public List<Store__c> storeSelect{get; set;}
public List<Account> accounts{get; set;}
public List<User> users{get; set;}

public Integer count{get; set;}
public boolean noAbsences{get; set;}
public boolean listEnabler{get; set;}
public boolean selectListEnabler{get; set;}
public String user{get; set;}
public String storeSelected{get; set;}
public String employeeSelected{get; set;}
public String sStartDate{get; set;}
public String sEndDate{get; set;}
public Date startDate{get; set;}
public Date endDate{get; set;}

public attendance_controller() {
user = UserInfo.getUserId();
//user = '005L0000000O0zEIAS';
}

public List<SelectOption> getStore() {

List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('--None--','--None--'));
storeSelect = [Select Id, Name FROM Store__c];
if (storeSelect.size()>0){
for (Integer j=0;j<storeSelect.size();j++)
      {
          options.add(new SelectOption(storeSelect[j].Id,storeSelect[j].Name));
      }
}
return options;
}
public PageReference searchAbsences() {
listEnabler = TRUE;  
sStartDate= Apexpages.currentPage().getParameters().get('startDateA');
sEndDate= Apexpages.currentPage().getParameters().get('endDateA');
   
   String[] myDateOnly = sStartDate.split(' ');
   String[] strDate = myDateOnly[0].split('/');
   Integer myIntDate = integer.valueOf(strDate[0]);
   Integer myIntMonth = integer.valueOf(strDate[1]);
   Integer myIntYear = integer.valueOf(strDate[2]);
   startDate = Date.newInstance(myIntYear, myIntMonth, myIntDate);

   myDateOnly = sEndDate.split(' ');
   strDate = myDateOnly[0].split('/');
   myIntDate = integer.valueOf(strDate[0]);
   myIntMonth = integer.valueOf(strDate[1]);
   myIntYear = integer.valueOf(strDate[2]);
   endDate= Date.newInstance(myIntYear, myIntMonth, myIntDate);
   
listAttendance=[Select Id, Name, User__c, Date_of_inattendance__c, Account_Id__c, Employee_Name__c, Excused_Absence__c FROM Attendance_Record__c WHERE User__c = :employeeSelected AND Date_of_inattendance__c <= :endDate AND Date_of_inattendance__c >= :startDate];
count=listAttendance.size();

if (count==0) noAbsences=TRUE;

return null;
}

public PageReference enableTable() {
listEnabler = TRUE; 
return null;
}


public PageReference searchEmployees() {
selectListEnabler=TRUE;
return null;
}

public List<SelectOption> getEmployees() {
List<SelectOption> options2 = new List<SelectOption>();
options2.add(new SelectOption('--None--','--None--'));
//[select id, (select id, status, comment__c, campaignid from CampaignMembers)from contact where id in (select contactId from campaignMember where campaignId in :cams];
accounts = [Select Id, Name FROM Account WHERE  Active__c = TRUE AND Current_Store__c = :storeSelected];
users = [Select Id, Name FROM User WHERE AccountId in :accounts];
//accounts = [Select Id, Name FROM Account WHERE Current_Store__c = :storeSelected];
//SELECT User.Id,User.UserName,User.isPortalEnabled, User.Email, Contact.FirstName, Contact.LastName FROM User u WHERE accountId IN (SELECT Id FROM Contact) 
if (users.size()>0){
for (Integer j=0;j<users.size();j++)
      {
          options2.add(new SelectOption(users[j].Id,users[j].Name));
      }
}
return options2;
}


public PageReference saveAndLoad() {
update listAttendance;
listAttendance=[Select Id, Name, User__c, Date_of_inattendance__c, Account_Id__c, Employee_Name__c, Excused_Absence__c FROM Attendance_Record__c WHERE User__c = :employeeSelected AND Date_of_inattendance__c <= :endDate AND Date_of_inattendance__c >= :startDate];
return null;
}

}